package hotciv.variants;

import hotciv.common.TileImpl;
import hotciv.framework.GameConstants;
import hotciv.framework.Position;
import hotciv.framework.Tile;
import hotciv.framework.TileMap;

public class DeltaTileMap implements TileMap {
	private Tile[][] tileMap;
	
	public DeltaTileMap(String[] map) {
		tileMap = new Tile[GameConstants.WORLDSIZE][GameConstants.WORLDSIZE];
		String line;
	    for ( int r = 0; r < GameConstants.WORLDSIZE; r++ ) {
	      line = map[r];
	      for ( int c = 0; c < GameConstants.WORLDSIZE; c++ ) {
	        char tileChar = line.charAt(c);
	        String type = "error";
	        if ( tileChar == '.' ) { type = GameConstants.OCEANS; }
	        if ( tileChar == 'o' ) { type = GameConstants.PLAINS; }
	        if ( tileChar == 'M' ) { type = GameConstants.MOUNTAINS; }
	        if ( tileChar == 'f' ) { type = GameConstants.FOREST; }
	        if ( tileChar == 'h' ) { type = GameConstants.HILLS; }
	        tileMap[c][r] = new TileImpl(new Position(r, c), type);
	      }
	    }
	}
	
	@Override
	public Tile getTileAt(Position p) {
		return tileMap[p.getColumn()][p.getRow()];
	}
	
}
